package com.vca.service.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vca.common.model.product.StoreProductAttrValue;
import com.vca.common.model.vca_product.VcaProductAttrValue;
import com.vca.service.dao.vca_product.VcaProductAttrValueDao;
import com.vca.service.service.VcaProductAttrValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品属性值表 服务实现类
 * </p>
 *
 * @author chenBing
 * @since 2022-11-16
 */
@Service
public class VcaProductAttrValueServiceImpl extends ServiceImpl<VcaProductAttrValueDao, VcaProductAttrValue> implements VcaProductAttrValueService {

    @Autowired
    private VcaProductAttrValueDao dao;

    /**
     * @param shopId    商品ID
     * @param shopType 商品类型
     * @Description:处理商品属性详情
     * @Author: chenBing
     * @Date: 2022/11/18
     */
    @Override
    public List<VcaProductAttrValue> getListByProductIdAndType(Integer shopId, Integer shopType) {
        LambdaQueryWrapper<VcaProductAttrValue> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VcaProductAttrValue::getProductId,shopId);
        lqw.eq(VcaProductAttrValue::getType,shopType);
        lqw.eq(VcaProductAttrValue::getIsDeleted,false);
        return list(lqw);
    }

    /**
     * @Description:商品属性集合
     * @Author: chenBing
     * @Date: 2022/11/21
     */
    @Override
    public List<VcaProductAttrValue> getListByProductIdAndAttrId(Integer productId, String attrId, Integer type) {
        LambdaQueryWrapper<VcaProductAttrValue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(VcaProductAttrValue::getProductId, productId);
        lambdaQueryWrapper.eq(VcaProductAttrValue::getType, type);
        if(null != attrId){
            lambdaQueryWrapper.eq(VcaProductAttrValue::getId, attrId);
        }
        lambdaQueryWrapper.eq(VcaProductAttrValue::getIsDeleted, false);
        return list(lambdaQueryWrapper);
    }

    /**
     * @param attrValueId 商品规格属性值id
     * @param productId 商品id
     * @param productType 商品类型
     * @Description:查询商品规格属性值信息
     * @Author: chenBing
     * @Date: 2022/11/22
     */
    @Override
    public VcaProductAttrValue getByIdAndProductIdAndType(Integer attrValueId, Integer productId, Integer productType) {
        LambdaQueryWrapper<VcaProductAttrValue> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VcaProductAttrValue::getId, attrValueId);
        lqw.eq(VcaProductAttrValue::getProductId, productId);
        lqw.eq(VcaProductAttrValue::getType, productType);
        lqw.eq(VcaProductAttrValue::getIsDeleted, false);
        return getOne(lqw);
    }

    /**
     * 根据商品属性查询
     *
     * @param vcaProductAttrValue 商品属性参数
     * @return 商品属性结果
     */
    @Override
    public List<VcaProductAttrValue> getByEntity(VcaProductAttrValue vcaProductAttrValue) {
        LambdaQueryWrapper<VcaProductAttrValue> lqw = new LambdaQueryWrapper<>();
        lqw.setEntity(vcaProductAttrValue);
        return dao.selectList(lqw);
    }

    /**
     * 删除商品规格属性值
     * @param productId 商品id
     * @param type 商品类型
     * @return Boolean
     */
    @Override
    public Boolean deleteByProductIdAndType(Integer productId, Integer type) {
        LambdaUpdateWrapper<VcaProductAttrValue> luw = Wrappers.lambdaUpdate();
        luw.set(VcaProductAttrValue::getIsDeleted, true);
        luw.eq(VcaProductAttrValue::getProductId, productId);
        luw.eq(VcaProductAttrValue::getType, type);
        return update(luw);
    }

}
